from paddlemix.datacopilot.core import MMDataset
from paddlemix.datacopilot.ops.filter._image_ration_filter import image_ration_filter

# Path to the dataset
anno_path = 'random_samples.json'

# Load the dataset
print("Loading the dataset...")
dataset = MMDataset.from_json(anno_path)
print("Initial dataset size:", len(dataset))

# Apply the image aspect ratio filter operator
dataset = dataset.image_ration_filter(
    min_ratio=0.333,  # Minimum aspect ratio
    max_ratio=3.0     # Maximum aspect ratio
)

# Print the size of the filtered dataset
print("Filtered dataset size:", len(dataset))
print("Image aspect ratio filtering complete.")

# Export the filtered dataset
dataset.export_json(anno_path.replace('.json', '_aspect_ratio_filtered.json'))